package com.jwthhealth_pub.old.sportfitness.presenter;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;

import com.jwthhealth_pub.old.api.ApiHelper;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.sportfitness.module.SportHomeModule;
import com.jwthhealth_pub.old.sportfitness.view.SportFitnessHomeActivity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/1/4.
 */

public class ISportHomePresenterCompl implements ISportHomePresenter {

    SportFitnessHomeActivity activity;

    public ISportHomePresenterCompl(SportFitnessHomeActivity activity) {
        this.activity = activity;
    }

    @Override
    public void getData() {
        final Call<SportHomeModule> sportHomeModuleCall = ApiHelper.sportTopRequest();
        sportHomeModuleCall.enqueue(new Callback<SportHomeModule>() {
            @Override
            public void onResponse(Call<SportHomeModule> call, Response<SportHomeModule> response) {
                SportHomeModule module =  response.body();;
                if (module.getCode().equals("0")){
                    Message message = new Message();
                    message.what = SportFitnessHomeActivity.SPORT_HOME_DATA;
                    Bundle bundle = new Bundle();
                    bundle.putSerializable(Constant.SPORT_DATA, module);
                    message.setData(bundle);
                    activity.mHandler.sendMessage(message);
                }else {
                    Log.d("ISportHomePresenterComp", "fail");
                }
            }

            @Override
            public void onFailure(Call<SportHomeModule> call, Throwable t) {
                Log.d("ISportHomePresenterComp", "error");
            }
        });
    }
}
